package com.xinqi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinqi.dto.BlogCommentDto;
import com.xinqi.dto.Result;
import com.xinqi.entity.Blog;
import com.xinqi.entity.BlogComment;
import com.xinqi.service.BlogCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xin麒
 * @date 2023/6/25 22:32
 */
@Slf4j
@RestController
@RequestMapping("/blogComment")
@Api("博客评论模块")
public class BlogCommentController {
    @Autowired
    private BlogCommentService blogCommentService;
    @GetMapping("{page}/{limit}")
    public Result findPageQueryBook(@PathVariable Long page, @PathVariable Long limit  ) {
        //创建page对象
        Page<BlogComment> pageParam = new Page<>(page,limit);
        //调用service方法
        List<BlogComment> pageModel =  blogCommentService.getPageByLimitedAndPage(pageParam);
        //返回
        return Result.ok(pageModel);
    }

    @GetMapping("/{id}")
    @ApiOperation("blogComment信息,获取博客id这篇博客的所有博客的评论信息")
    public Result get(@PathVariable("id") Long id){
        List<BlogCommentDto> blogComments = blogCommentService.getTreeByBlogId(id);
        return Result.ok(blogComments);
    }



}

